import * as mine from "../../api/mine";
import validate from "../../utils/validate";

Page({
    data: {
        mobile:""
    },
    onLoad(options){
        this.setData({
            mobile:options.mobile
        })
    },
    getValue(e){
        this.setData({
            mobile:e.detail.value
        })
    },
    submit(){

        if(!this.data.mobile){
            wx.showToast({
                title: '请输入手机号',
                icon: 'none'
            });
            return;
        }

        if( !validate.mobile.test( this.data.mobile ) ){
            wx.showToast({
                title: '手机号格式错误',
                icon:"none",
                duration: 1500,
                mask: true,
            });
            return;
        }

        mine.modifyMobile({
            mobile:this.data.mobile
        })
            .then(()=>{
                wx.navigateBack({
                    delta: 1
                });
            })
    }
})
